(function($){
	 function formResult(msg, state) {
	        layer.closeAll();
	        if(state == 0) {
	            layer.alert(msg, {icon: 5});
	        } else {
	            layer.confirm(msg, {icon: 6, title:'系统提示', btn: ['确定']}, function(index){
	                location.href = $('#form_add').attr('urlList')
	            });
	        }
	    }
    function refreshUser(parame){
        $("select[name='user_id']").html("");
        var html = '';
        for(var i= 0;i < parame.length;i++){
            var data = parame[i];
            html += "<option value='"+data.user_id+"'>"+ data.user_nickname +"</option>";
        }
        $("select[name='user_id']").html(html);
    }
    $(function(){
        window.formResult = formResult;
        window.refreshUser = refreshUser;
    	$("#form_add").submit(function(){
    		layer.load();
            form.submit();
    	})
    	$(".reply").click(function(){
    		var _this = $(this);
    		var type = _this.attr('type');
    		var username = _this.attr('duser');
    		var drole = _this.attr('drole');
			if(drole) {
				$('#picGroup').hide();
			} else {
				$('#picGroup').show();
			}
    		if(type == 3 || type == 5 || type == 6){
    			var answer = _this.attr('danswer');
    			$("#answer").val(answer);
    		}
            if(type == 5 || type == 6){
                var to_user_id = _this.attr('duid');
                $("input[name='to_user_id']").val(to_user_id);
            }
    		$("#type").val(type);
    		$("#role").html(username);
    	});
        $("input[name='search_user']").change(function() {
            var username = $("input[name='search_user']").val();
            $.ajax({
                type:'POST',
                dataType:'json',
                url:'/manage/questionmanage/searchuser',
                data:{search_user:username},
                success:function (data){
                    refreshUser(data.list);
                }
            })
        });
    	$(".answer_del").click(function(){
    		var url = $(this).attr('durl');
    		var message = "是否删除此条回复？";
    		layer.confirm(message, {
    		    btn: ['是','否'] //按钮
    		}, function(){
    		    window.ifr_send_file.location.href=url;
    		});
    	})
        $(".answer_dels").click(function(){
            var url = $(this).attr('durl');
            var message = "是否删除此条回复？";
            layer.confirm(message, {
                btn: ['是','否'] //按钮
            }, function(){
                window.top.location.href=url;
            });
        })
    	
    });
})(jQuery);